[−][src]Crate sipmsg
Introduction
Library for parsing/editing/constructing SIP requests and responses.
This is the very first version where only simple parsing is support.
Example
use sipmsg::*; let invite_msg_buf = "\ INVITE sip:bob@biloxi.com;user=phone?to=alice%40atlanta.com&priority=urgent SIP/2.0\r\n\ Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKkjshdyff\r\n\ Via: SIP/2.0/UDP 192.168.1.111\r\n\ To: Bob <sip:bob@biloxi.com>\r\n\ From: Alice <sip:alice@atlanta.com>;tag=88sja8x\r\n\ Max-Forwards: 70\r\n\ Call-ID: 987asjd97y7atg\r\n\ Extention-Header: extention header value;param=123;without_value\r\n\ CSeq: 986759 INVITE\r\n\r\nbody_stuff" .as_bytes(); // First parameter not realized yet. // It should consist be residue if Content-Length is less then actual body length. let (_, request) = SipRequest::parse(invite_msg_buf).unwrap(); assert_eq!(request.rl.method, SipRequestMethod::INVITE); assert_eq!(request.rl.sip_version, SipVersion(2, 0)); // RURI assert_eq!(request.rl.uri.scheme, SipRequestUriScheme::SIP); assert_eq!(request.rl.uri.user_info().unwrap().value, "bob"); assert_eq!(request.rl.uri.hostport.host, "biloxi.com"); assert_eq!(request.rl.uri.params().unwrap().get(&"user"), Some((&SipAscii::new("user"), &Some("phone")))); assert_eq!(request.rl.uri.headers().unwrap().get(&"to"), Some(&"alice%40atlanta.com")); assert_eq!(request.rl.uri.headers().unwrap().get(&"priority"), Some(&"urgent")); // Via Header let via_headers = request.headers.get_rfc(SipRFCHeader::Via).unwrap(); assert_eq!(via_headers[1].value, "SIP/2.0/UDP pc33.atlanta.com"); assert_eq!( via_headers[1].params().unwrap().get(&"branch"), Some((&SipAscii::new("branch"), &Some("z9hG4bKkjshdyff"))) ); assert_eq!(via_headers[0].value, "SIP/2.0/UDP 192.168.1.111"); assert_eq!( via_headers[1].params().unwrap().get(&"branch"), Some((&SipAscii::new("branch"), &Some("z9hG4bKkjshdyff"))) ); assert_eq!( via_headers[1].params().unwrap().get(&"notExistParam"), None ); // Extention Header let extention_header = request.headers.get_ext_s("extention-header").unwrap(); assert_eq!(extention_header.name, "extention-header"); assert_eq!(extention_header.value, "extention header value"); assert_eq!( extention_header.params().unwrap().get(&"param"), Some((&SipAscii::new("param"), &Some("123"))) ); assert_eq!( extention_header.params().unwrap().get(&"without_value"), Some((&SipAscii::new("without_value"), &None)) ); // Body assert_eq!(request.body.unwrap(), "body_stuff".as_bytes());
Re-exports
pub use common::errorparse; |
pub use common::traits::NomParser; |
Modules
common | |
generic_params | |
sipuri | |
traits |
Macros
sip_parse_error |
Structs
GenericParams | |
SipAscii | Case Insensitive wrapper of Ascii strings. |
SipHeader | |
SipHeaders | |
SipRequest | |
SipRequestLine | Ex: |
SipResponse | |
SipResponseStatusLine | Ex: |
SipUri | Its general form, in the case of a SIP URI, is: sip:user:password@host:port;uri-parameters?headers |
SipVersion | SIP-Version
ex. |
Enums
SipMessageType | |
SipRFCHeader | Headers that defined in rfc3261 |
SipRequestMethod | |
SipRequestUriScheme | |
SipResponseStatusCode |
Functions
get_sip_message_type | Fast determinates message type and minimal validate for further transmission to suitable parser. Does not validate full first line, just first 3 bytes. |